package cn.com.zhuxulin.info.Forms;

import java.io.IOException;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.ImageItem;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.ItemCommandListener;
import javax.microedition.lcdui.ItemStateListener;
import javax.microedition.midlet.MIDlet;

import cn.com.zhuxulin.info.Lists.ProvicesList;

public class Start extends Form {
	//private Display display = null;
	private Command ok = null;
	private Command exit = null;
	private ImageItem imgQQ = null;
	private ImageItem imgMobile = null;
	private ImageItem imgIP = null;
	private ImageItem imgWeather = null;

	public Start(final Display display,final MIDlet start) {
		super("Powered By ZhuXulin");
		//this.display=display;
		ok = new Command("OK", Command.OK, 1);
		exit = new Command("Exit", Command.EXIT, 1);
		try {
			imgWeather = new ImageItem(null, Image.createImage("/WeatherInfo.png"), ImageItem.LAYOUT_CENTER | ImageItem.LAYOUT_NEWLINE_AFTER, "AltText");
			imgQQ = new ImageItem(null, Image.createImage("/QQInfo.png"), ImageItem.LAYOUT_CENTER | ImageItem.LAYOUT_NEWLINE_AFTER, "AltText");
			imgMobile = new ImageItem(null, Image.createImage("/MobileInfo.png"), ImageItem.LAYOUT_CENTER | ImageItem.LAYOUT_NEWLINE_AFTER, "AltText");
			imgIP = new ImageItem(null, Image.createImage("/IPInfo.png"), ImageItem.LAYOUT_CENTER | ImageItem.LAYOUT_NEWLINE_AFTER, "AltText");
		} catch (IOException e) {
			e.printStackTrace();
		}
		imgQQ.addCommand(ok);
		imgMobile.addCommand(ok);
		imgIP.addCommand(ok);
		imgWeather.addCommand(ok);

		this.addCommand(exit);
		this.append(imgWeather);
		this.append(imgQQ);
		this.append(imgMobile);
		this.append(imgIP);

		imgQQ.setItemCommandListener(new ItemCommandListener() {
			public void commandAction(Command cmd, Item item) {
				display.setCurrent(new QQ(display,Start.this));
			}
		});
		imgMobile.setItemCommandListener(new ItemCommandListener() {
			public void commandAction(Command cmd, Item item) {
				display.setCurrent(new Mobile(display,Start.this));
			}
		});
		imgIP.setItemCommandListener(new ItemCommandListener() {
			public void commandAction(Command cmd, Item item) {
				display.setCurrent(new IP(display,Start.this));
			}
		});
		imgWeather.setItemCommandListener(new ItemCommandListener() {
			public void commandAction(Command cmd, Item item) {
//				display.setCurrent(new Weather(display,Start.this,"3112"));
				new Thread(new Runnable() {
					public void run() {
						display.setCurrent(new ProvicesList(display, Start.this));
					}
				}).start();
			}
		});
		this.setCommandListener(new CommandListener() {
			public void commandAction(Command cmd, Displayable arg) {
				if(cmd==exit){
					start.notifyDestroyed();
				}
			}
		});
		this.setItemStateListener(new ItemStateListener() {
			public void itemStateChanged(Item item) {
				System.out.println("changed!");
			}
		});
	}
}
